package com.mmlc.meimei.lichengkongjian.home;

import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.TextView;

import com.androidnetframe.httputil.BaseRequestFilterLayer;
import com.androidnetframe.responsejavabean.RequestError;
import com.androidnetframe.utils.DateUtils;
import com.mmlc.inter.InterActivity;
import com.mmlc.meimei.lichengkongjian.R;
import com.mmlc.network.filter.ActiveInfoDetailRequestFilter;
import com.mmlc.network.responsebean.ActiveInfoDetailResponseBean;
import com.mmlc.utils.ViewUtils;

/**
 * description: 资讯详情 (未用)
 * by king
 * Created at 2016/8/26 13:10
 */
public class FashionInfoDetailActivity extends InterActivity {

    @Override
    protected int initContentView() {
        return R.layout.activity_fashion_info_detail;
    }

    String id, title, htmlUrl;

    @Override
    protected void initExtra() {
        super.initExtra();
        id = getIntent().getStringExtra("id");
        title = getIntent().getStringExtra("title");
        htmlUrl = getIntent().getStringExtra("url");
    }

    WebView web_html;
    TextView tv_title, tv_name, tv_time, tv_read;

    @Override
    protected void initView() {
        web_html = ViewUtils.getView(activity, R.id.web_html);
        tv_title = ViewUtils.getView(activity, R.id.tv_title);
        tv_name = ViewUtils.getView(activity, R.id.tv_name);
        tv_time = ViewUtils.getView(activity, R.id.tv_time);
        tv_read = ViewUtils.getView(activity, R.id.tv_read);
    }

    @Override
    protected void initInfo() {
        super.initInfo();
        ActiveInfoDetailRequestFilter filter = new ActiveInfoDetailRequestFilter(activity);
        filter.requestBean.id = id;
        filter.sendRequest(new BaseRequestFilterLayer.AccessResultFromFilter<ActiveInfoDetailResponseBean>() {
            @Override
            public void onSuccess(ActiveInfoDetailResponseBean result) {
                if (null == result.getData()) return;
                if (!ViewUtils.isEmpty(result.getData().getName()))
                    tv_name.setText(result.getData().getName());
//                    tv_title.setText(result.getData().getName());

                if (!ViewUtils.isEmpty(result.getData().getAdd_time()))
                    tv_time.setText(DateUtils.changeDateStyle(result.getData().getAdd_time(), "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd"));

                if (!ViewUtils.isEmpty(result.getData().getClickcount()))
                    tv_read.setText("阅读 " + result.getData().getClickcount());

                web_html.getSettings().setJavaScriptEnabled(true);
                web_html.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
                web_html.getSettings().setUserAgentString(web_html.getSettings().getUserAgentString() + "mmlc.meiqi");
                web_html.setWebChromeClient(new WebChromeClient());
                web_html.getSettings().setSupportZoom(true);
                web_html.getSettings().setDisplayZoomControls(false);
                web_html.getSettings().setBuiltInZoomControls(false);
                web_html.getSettings().setUseWideViewPort(true);
                web_html.getSettings().setLoadWithOverviewMode(true);
                web_html.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
//                web_html.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
                web_html.requestFocus();
                web_html.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);

                if (!ViewUtils.isEmpty(htmlUrl)) web_html.loadUrl(htmlUrl);
                else if (!ViewUtils.isEmpty(id))
                    web_html.loadUrl("http://wx.lolever.com/html/info_details.html?id=" + id);
//                if (!ViewUtils.isEmpty(result.getData().getContent()))
//                    web_html.loadDataWithBaseURL(null, result.getData().getContent(), "text/html", "utf-8", null);
            }

            @Override
            public void onFailed(View errorLayout, RequestError serverError, int failedType) {

            }
        });
    }
}
